<?xml version="1.0" encoding="UTF-8"?>
<!-- ===============================================================

This stylesheet adds hash attribute to every <technology> tag found
in the Eagle library file.
This hash is than used by another template to enumerate all devices,
assuming that devices with the same characteristics shall have the same
number.

-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes" doctype-system="eagle.dtd" />

<xsl:strip-space elements="*"/>



<xsl:template match="node()|@*">
   <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
</xsl:template>


<!-- ================================================================
 |
 + ================================================================== -->
<xsl:template match="/">
   <xsl:call-template name="root.messages"/>
   <xsl:apply-templates/>
</xsl:template>

<!-- ================================================================
 |
 + ================================================================== -->
<xsl:template name="root.messages">
   <xsl:message>============================================================</xsl:message>
   <xsl:message> Adding hash key to each technology tag                     </xsl:message>
   <xsl:message>                                                            </xsl:message>
   <xsl:message> AUTHOR : martin.sveda@saabgroup.com                        </xsl:message>
   <xsl:message> USING  :<xsl:value-of select="system-property('xsl:vendor')"/></xsl:message>
   <xsl:message>============================================================</xsl:message>
   <xsl:message>                                                            </xsl:message>
</xsl:template>

<!-- =================================================================
 |   
 |
 +   ================================================================= -->
<xsl:template match="/eagle/drawing/library/devicesets/deviceset/devices/device/technologies">
   <xsl:copy>
      <xsl:for-each select="technology">
         <xsl:element name="technology">
            <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
            <xsl:attribute name="hash"><xsl:value-of select="concat(attribute[@name='COMPONENT_PACKAGE']/@value, '+', attribute[@name='COMPONENT_VALUE']/@value, '+', @name)" /></xsl:attribute>
            <xsl:apply-templates/>
         </xsl:element>
      </xsl:for-each>
   </xsl:copy>   
</xsl:template>

</xsl:stylesheet> 
